﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Snowdreamist.Windows.Navigation.Primitives
{
    public class NavigationSwitcher
    {
        public NavigationSwitcher()
        {
        }

        public void Switch(Session session, object newViewModel, object newView)
        {
            INavigationAware aware = null;

            if (session != null && session.Current != null)
            {
                aware = session.Current.Frame.ContentViewModel as INavigationAware;
                if (aware != null)
                    aware.NavigateFrom(session);
                aware = session.Current.Frame.ContentView as INavigationAware;
                if (aware != null)
                    aware.NavigateFrom(session);
            }

            aware = newViewModel as INavigationAware;
            if (aware != null)
                aware.NavigateTo(session);
            aware = newView as INavigationAware;
            if (aware != null)
                aware.NavigateTo(session);
        }
    }
}